/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package shaman.storage.impl.file;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

/**
 *
 * @author dmitriy
 */
@XStreamAlias("block")
public class StoredBlock implements Comparable<StoredBlock> {

    @XStreamAsAttribute
    private long offset;

    @XStreamAsAttribute
    private long length;

    private String stream;

    public StoredBlock() {
    }

    public StoredBlock(long offset, long length, String stream) {
        this.offset = offset;
        this.length = length;
        this.stream=stream;
    }

    public long getOffset() {
        return offset;
    }

    public long getLength() {
        return length;
    }

    public String getStream() {
        return stream;
    }

    public int compareTo(StoredBlock o) {
        long offset2=o.getOffset();
        if (offset<offset2)
            return -1;
        else if (offset>offset2)
            return 1;
        else {
            long length2=o.getLength();
            if (length<length2)
                return -1;
            else if (length>length2)
                return 1;
        }
        return 0;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj==null)
            throw new NullPointerException("Comparing with a null");
        if (obj instanceof StoredBlock)
        {
            StoredBlock blk2=(StoredBlock) obj;
            if (blk2.getOffset()==offset && blk2.getLength()==length)
                return true;
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 13 * hash + (int) (this.offset ^ (this.offset >>> 32));
        hash = 13 * hash + (int) (this.length ^ (this.length >>> 32));
        return hash;
    }

}
